package com.example.androidclasseight.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.androidclasseight.R;
import com.example.androidclasseight.bean.PYQBean;
import com.example.androidclasseight.myadapter.ChatAdapter;

import java.util.LinkedList;

public class chatFragment extends Fragment {

    private View rootView;
    private LinkedList<PYQBean> pyqBeans;


    public static chatFragment newInstance(String param1) {
        chatFragment fragment = new chatFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_chat, container, false);

        //数据初始化
        pyqBeans = new LinkedList<>();
        for (int i = 0; i < 10; i++) {
            PYQBean pyqBean = new PYQBean(getResources().getDrawable(R.drawable.img),"女生"+i+"号","12312312332",getResources().getDrawable(R.drawable.sun),i+"分钟前");
            pyqBeans.add(pyqBean);
        }

        initPage(rootView);


        return rootView;
    }

    private void initPage(View root) {
        RecyclerView rl = root.findViewById(R.id.frag1_rv);
        ChatAdapter chatAdapter = new ChatAdapter(getContext(), pyqBeans);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        rl.setLayoutManager(linearLayoutManager);
        rl.setAdapter(chatAdapter);

    }

}